//
//  BQShopTableViewCell.m
//  BeeQuick
//
//  Created by Asun on 2017/7/10.
//  Copyright © 2017年 BecomeRich. All rights reserved.
//

#import "BQShopTableViewCell.h"
#import "BQShopCollectionViewCell.h"
#import "UIColor+MLAddition.h"
@interface BQShopTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property (strong, nonatomic)UICollectionView * collectionView;

@end

@implementation BQShopTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return  self;

}


- (void)setupUI{
 UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];

    flowLayout.minimumLineSpacing = 5;
    flowLayout.minimumInteritemSpacing = 1;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    
    CGFloat width = ([UIScreen mainScreen].bounds.size.width - 5) / 2;
    
    flowLayout.itemSize = CGSizeMake(width, 245);
    
    
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:flowLayout];
    
    self.collectionView = collectionView;
    
    collectionView.backgroundColor = [UIColor whiteColor];
    
    collectionView.dataSource = self;
    
    collectionView.delegate = self;
    
   // collectionView.scrollEnabled = NO;
    
    [collectionView registerNib:[UINib nibWithNibName:@"BQShopCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"Identifier"];
    
    [self.contentView addSubview:collectionView];
    
    [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(self.contentView);
        
    }];
    


}
-(void)setShopModelAry:(NSArray<BQShop *> *)shopModelAry{
    _shopModelAry = shopModelAry;
    [self.collectionView reloadData];
}

#pragma mark
#pragma mark - (每个CollectionView 有多少组)
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return 1;
}
#pragma mark
#pragma mark - (每一组有多少行)
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
 
 return self.shopModelAry.count;
}

#pragma mark
#pragma mark - (每一行cell 的显示)
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    

    
    BQShopCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Identifier" forIndexPath:indexPath];
    
    cell.shopModel = self.shopModelAry[indexPath.row];
    
    return cell;
}


@end
